package com.hz.ruoyilgorder.controller;

import com.github.pagehelper.PageInfo;

import com.hz.rouyigonggong.domain.LgDeliveryInfo;
import com.hz.rouyigonggong.domain.basedomain.BaseDomain;
import com.hz.rouyigonggong.domain.dto.LgDeliveryInfoDTO;
import com.hz.ruoyilgorder.config.LgDeliveryInfoConverter;
import com.hz.ruoyilgorder.service.LgDeliveryInfoService;
import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.common.core.utils.PageUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @version 1.0
 * @Author yzw
 * @Date 2025/3/10 11:00
 * @注释  出库车辆信息表
 */

@RestController
@RequestMapping("/carorder")
public class LgDeliveryInfoController {
@Autowired
private LgDeliveryInfoService lgDeliveryInfoService;



    @GetMapping("/getlist")
    public TableDataInfo getList(LgDeliveryInfoDTO entity){
        startPage();
        entity.setCreateBy(String.valueOf(BaseDomain.getUserId()));
        List<LgDeliveryInfoDTO> list = lgDeliveryInfoService.getList(entity);
        return  getDataTable(list);

    }
    /**
     * 根据订单id获取详细信息
     */
    @RequiresPermissions("carorder:every:query")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable Integer id) {

        return AjaxResult.success(lgDeliveryInfoService.getInfo(id));
    }

    @RequiresPermissions("carorder:every:edit")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody LgDeliveryInfoDTO orderDTO) {
        orderDTO.setCreateBy(String.valueOf(BaseDomain.getUserId()));
        //转换
        LgDeliveryInfo entity = LgDeliveryInfoConverter.toEntity(orderDTO);
        return AjaxResult.success(lgDeliveryInfoService.updateById(entity));
    }
    @RequiresPermissions("carorder:every:remove")
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {

        return AjaxResult.success(lgDeliveryInfoService.removeByIds(Arrays.asList(ids)));
    }




































    protected void startPage()
    {
        PageUtils.startPage();
    }
    protected TableDataInfo getDataTable(List<?> list)
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setRows(list);
        rspData.setMsg("查询成功");
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }
}
